package com.leyou.item.service.mapper;

import com.leyou.common.bean.IBaseMapper;
import com.leyou.item.inter.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface BrandMapper extends IBaseMapper<Brand> {

    @Insert("INSERT INTO tb_category_brand(category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertBrandAndCategory(@Param("cid") Long cid, @Param("bid") Long bid);

    @Delete("DELETE from tb_category_brand where brand_id = #{bid}")
    int deleteBrandAndCategory(@Param("bid") Long bid);

    @Select("SELECT b.* from tb_brand b INNER JOIN tb_category_brand cb on b.id=cb.brand_id where cb.category_id=#{cid}")
    List<Brand> selectBrandByCid(Long cid);

    @Select("select * from tb_brand order by id desc LIMIT 1")
    Brand getNewestId();
}